home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The Atari Compendium
/
The Atari Compendium (Toad Computers) (1994).iso
/
files
/
umich
/
telecomm
/
uemlsrc.arc
/
misc.c
< prev
next >
Wrap
C/C++ Source or Header
|
1987-08-24
|
16KB
|
573 lines
/* misc.c miscellaneous commands, some macros and mode commands */
#include <stdio.h>
#include <ctype.h>
#include <osbind.h>
#include "ed.h"
typedef short boolean;
static int count = 1;
char *modes[] = {"Fundamental","Wrap","C"};
/* MINDNL : META command Indent subsequent newline same as the present
* one. Bound to M-J.
*/
mindnl(f, n)
register int f, n;
{
curwp->w_doto = llength(curwp->w_dotp);
return(indent(f, n));
}
/* MDELELN : CTRL command Delete entire line from beginning. Bound to ^K.
*/
mdeleln(f, n)
register int f, n;
{
curwp->w_doto = 0;
return(kill(NULL, 1));
}
/* MDELWLN : META command Delete entire line including NL. Bound to M-^K.
*/
mdelwln(f, n)
register int f, n;
{
curwp->w_doto = 0;
return(kill(TRUE, 1));
}
/* MDELIND : META command Delete beginning indentation on line. Bound to M-\.
*/
mdelind(f, n)
register f, n;
{
register int odo;
f = llength(curwp->w_dotp);
odo = curwp->w_doto;
curwp->w_doto = 0;
while ((n = lgetc(curwp->w_dotp, curwp->w_doto)) <= ' '
&& curwp->w_doto != llength(curwp->w_dotp))
if (forwdel(NULL, 1) == FALSE)
return(FALSE);
if ((n = llength(curwp->w_dotp)) == NULL)
curwp->w_doto = n;
else {
if (odo == NULL)
curwp->w_doto = odo;
else
curwp->w_doto = odo - (f - n);
}
lchange(WFEDIT);
return(TRUE);
}
/* CLOWSP Meta Command Close up white space from point forward.
* Bound to M-^O.
*/
clowsp(f, n)
register int f, n;
{
while ((n = lgetc(curwp->w_dotp, curwp->w_doto)) <= ' '
|| curwp->w_doto == llength(curwp->w_dotp))
if(forwdel(NULL, 1) == FALSE)
return(FALSE);
return(linsert(1, ' '));
}
/* MARKPAR : Meta Command Mark paragraph for moving or deleting. Bound to
* M-H.
*/
markpar(f, n)
register int f, n;
{
goteop(NULL, n);
setmark(NULL, 1);
gotbop(NULL, n);
return(TRUE);
}
/* KILLSENT : Meta command Kills sentence forward. Bound to M-K.
*/
killsent(f, n)
register int f, n;
{
setmark(NULL,1);
forwsent(f, n);
return(killregion(NULL, 1));
}
/* TGLCASE : Meta command Toggles case of letter at point. Bound to M-^P.
*/
tglcase(f, n)
register int f, n;
{
register int c;
if (n < 0)
return(FALSE);
while(n--)
{
c = lgetc(curwp->w_dotp, curwp->w_doto);
if(islower(c))
c = toupper(c);
else
c = tolower(c);
lputc(curwp->w_dotp, curwp->w_doto, c);
lchange(WFEDIT);
if(forwchar(FALSE, 1) == FALSE)
return(FALSE);
}
return(TRUE);
}
/* GRTW eXtended command Globally removes trailing white space. Bound to
* ^X-\.
*/
grtw(f, n)
register int f, n;
{
register int dlo, d;
register LINE *dlp;
dlp = curwp->w_dotp;
dlo = curwp->w_doto;
gotobob(NULL, 1);
while((d = ltrw(FALSE, 1)) != EOF)
forwline(NULL, 1);
if (dlo > llength(dlp))
dlo = llength(dlp);
curwp->w_dotp = dlp;
curwp->w_doto = dlo;
curwp->w_flag |= WFHARD;
return(TRUE);
}
/* LTRW internal function delete trailing white space on current line.
* called by grtw() and fillpar(). Any arguments are ignored. Returns
* length of line or EOF at end of buffer.
*/
ltrw(f, n)
register int f, n;
{
register int c, d;
if(curwp->w_dotp == curbp->b_linep)
return(EOF);
d = llength(curwp->w_dotp);
curwp->w_doto = d;
if (d == NULL)
return(NULL);
while (--d >= 0)
{
backchar(FALSE, 1);
c = lgetc(curwp->w_dotp, curwp->w_doto);
if(c != ' ' && c != '\t')
break;
if(ldelete(1, NULL) == FALSE)
return(EOF);
}
return(llength(curwp->w_dotp));
}
/* TWADDLE Meta command More at twiddle. Transpose two words on a line.
* Bound to M-T.
*/
twaddle(f, n)
register int f, n;
{
boolean flag = FALSE;
boolean punct= FALSE;
register int c;
char word[20];
n = 0;
if(backchar(FALSE, 1) == FALSE)
return (FALSE);
c = lgetc(curwp->w_dotp, curwp->w_doto);
if(ispunct(c))
{
punct = c;
if (forwdel(NULL, 1) == FALSE)
return (FALSE);
}
else if (forwchar(FALSE, 1) == FALSE)
return (FALSE);
c = lgetc(curwp->w_dotp, curwp->w_doto);
if (isspace(c))
flag = c;
else if (ispunct(c))
flag = c;
else
word[n++] = c;
if (ldelete(1, NULL) == FALSE)
return (FALSE);
while(c = lgetc(curwp->w_dotp, curwp->w_doto))
{
if (curwp->w_doto == llength(curwp->w_dotp))
break;
if (isalnum(c))
{
word[n++] = c;
if (forwdel(NULL, 1) == FALSE)
return (FALSE);
}
else
break;
}
if(backword(NULL, 1) == FALSE)
return (FALSE);
c = 0;
while(n--)
if (linsert(1, word[c++]) == FALSE)
return (FALSE);
if (punct)
if (linsert(1, punct) == FALSE)
return (FALSE);
if (flag)
if (linsert(1, flag) == FALSE)
return (FALSE);
return(TRUE);
}
/* MRFLUSH META Command right flush current line. Bound to M-^R */
mrflush(f, n)
register int f, n;
{
register short p; /* where we are in line */
register short l; /* length of line */
register short o; /* offset for new location */
p = curwp->w_doto;
if((l = llength(curwp->w_dotp)) == NULL)
return(FALSE);
if (fillcol)
f = fillcol;
else f = 80;
if((o = f - l) < 0)
return(FALSE);
curwp->w_doto = 0;
linsert(o, ' ');
forwchar(NULL, p);
return(TRUE);
}
/* MCENTER META Command center current line. Bound to M-^C */
mcenter(f, n)
register int f, n;
{
register short p; /* where we are in line */
register short l; /* length of line */
register short o; /* offset for new location */
p = curwp->w_doto;
if((l = llength(curwp->w_dotp)) == NULL)
return(FALSE);
if (fillcol)
f = fillcol;
else f = 80;
if((o = (f - l)/2) < 0)
return(FALSE);
curwp->w_doto = 0;
linsert(o, ' ');
forwchar(NULL, p);
return(TRUE);
}
/* SETMODE Extended Command. Only one mode at a time. Bound to ^X-M.
*/
setmode(f, n)
register int f, n;
{
char mymode[12];
register char *ptr;
extern char *index();
register BUFFER *bp;
register WINDOW *wp;
if((f=mlreply("New mode: ",mymode,12)) != TRUE)
return(f);
/* don't fail because of stray spaces */
if ((ptr=index(mymode,' '))!=NULL)
*ptr = '\0';
else if ((ptr=index(mymode,'\t'))!=NULL)
*ptr = '\0';
n = strlen(mymode);
/* adjust case */
for (f=0;f<=n;f++)
if (f == 0)
mymode[f] = toupper(mymode[f]);
else
mymode[f] = tolower(mymode[f]);
for (